package example.com.terry.servlet;

import example.com.terry.bean.UserDto;
import example.com.terry.utils.CookieUtils;
import example.com.terry.utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Date;

/**
 * ClassName: HbaseManager <br/>
 * Description: 用户查询 <br/>
 * Date: 2020/5/21 下午5:27 <br/>
 * <br/>
 *
 * @author ls
 * <p/>
 * 修改记录
 * @version 1.0<br />
 */
@WebServlet("/queryUserById")
public class QueryUserById extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (CookieUtils.isSign(req)) {
            String id = req.getParameter("id");
            String sql = "select * from tb_user where id = '" + id + "'";
            ResultSet resultSet = JDBCUtils.initQuery(sql);
            try {
                UserDto userDto = new UserDto();
                while (resultSet.next()) {
                    String id1 = resultSet.getString("id");
                    String username = resultSet.getString("username");
                    String password = resultSet.getString("password");
                    Date birthday = resultSet.getDate("birthday");
                    String age = resultSet.getString("age");
                    String sex = resultSet.getString("sex");
                    String clazz = resultSet.getString("clazz");
                    userDto.setAge(age);
                    userDto.setBirthday(birthday);
                    userDto.setClazz(clazz);
                    userDto.setId(id1);
                    userDto.setPassword(password);
                    userDto.setSex(sex);
                    userDto.setUsername(username);


                }
                resp.getWriter().println(userDto);
            } catch (Exception e) {

            }
        }
    }
}
